package com
{
	import com.container.GraphEditor;
	import com.controls.ActivityButtonBehaviour;
	import com.controls.DecisionButtonBehaviour;
	import com.controls.IButtonBehaviour;
	import com.controls.ToolButton;
	import com.controls.UpdateButtonBehaviour;
	import com.models.WorkFlow;
	
	import mx.core.Application;
	import mx.events.FlexEvent;
	import flash.events.KeyboardEvent;
	import mx.managers.CursorManager;
	import com.controls.SaveButtonBehaviour;
	import flash.ui.ContextMenu;
	import flash.display.MovieClip;
	import flash.ui.ContextMenuItem;

	/**
	 * Ursprungsklasse der Applikationen
	 * 
	 */
	public class MainApp extends Application
	{
		[Embed(source="/assets/icons/pencil_add.png")]
		public static const CREATE_ICON:Class;
		[Embed(source="/assets/icons/pencil_delete.png")]
		public static const DELETE_ICON:Class;
		[Embed(source="/assets/icons/connect.png")]
		public static const CONNECT_ICON:Class;
		
		private var _cursorId:int;
		private var _model:WorkFlow;
		
		/**
		 * Konstruktor
		 * 
		 */
		public function MainApp()
		{
			addEventListener(FlexEvent.INITIALIZE, initializeHandler);
			addEventListener(KeyboardEvent.KEY_DOWN, keyboardDownHandler);
			addEventListener(KeyboardEvent.KEY_UP, keyboardUpHandler);
		}
		
		//public
		
		//protected
		/**
		 * Behandlung des Initialize Events
		 * @param evt
		 * 
		 */
		protected function initializeHandler(evt:FlexEvent):void
		{
			paint();
			
		}
		
		//protected
		/**
		 * Erstellen der Elemente der Applikation
		 * 
		 */
		protected function paint():void
		{
			_model = new WorkFlow();
			var graphEditor:GraphEditor = new GraphEditor(_model);
			graphEditor.percentHeight = 100;
			graphEditor.percentWidth = 100;
			
			var activityButtonBehaviour:IButtonBehaviour = new ActivityButtonBehaviour();
			var activityButton:ToolButton = new ToolButton(activityButtonBehaviour, _model);
			
			var decisionButtonBehaviour:IButtonBehaviour = new DecisionButtonBehaviour();
			var decisionButton:ToolButton = new ToolButton(decisionButtonBehaviour, _model);
			
			var updateButtonBehaviour:IButtonBehaviour = new UpdateButtonBehaviour();
			var updateButton:ToolButton = new ToolButton(updateButtonBehaviour, _model);
			
			var saveButtonBehaviour:IButtonBehaviour = new SaveButtonBehaviour();
			var saveButton:ToolButton = new ToolButton(saveButtonBehaviour, _model);
			
			
			this["graphPanelControlBar"].addChild(activityButton);
			this["graphPanelControlBar"].addChild(decisionButton);
			this["graphPanelControlBar"].addChild(saveButton);
			
			this["attrPanelControlBar"].addChild(updateButton);
			
			graphEditor.setStyle("backgroundColor", 0xEEEEEE);
			this["graphPanel"].addChild(graphEditor);
			
			this["attrEditorAccordion"].model = _model; 
		}
		
		private function keyboardDownHandler(evt:KeyboardEvent):void
		{
			if(evt.shiftKey)
			{
				_model.tool = "delete";
			}
		}
		
		private function keyboardUpHandler(evt:KeyboardEvent):void
		{
			_model.tool = "";
		}
		
	}
}